﻿
namespace CmdArgs.Validation.Options
{
    using CmdArgs;
    using CmdArgs.Settings;

    /// <summary>
    /// Validates whether the parameters' values are in format 
    /// that can be parsed by method <see cref="CmdArgs.OptionParameterValue.AsBool()"/>.
    /// </summary>
    public sealed class BoolOptionValidator : ValueValidatorTemplate
    {
        protected override ValidationResult Validate(string value, OptionSettings option)
        {
            if (value.ToUpperInvariant() == "TRUE" || value == "1")
            {
                return ValidationResult.GetValidResult();
            }
            else
            {
                string message = string.Format("Value {0} is not boolean value. Use 'true' or 'false'.", value);
                return new ValidationResult(new ValidationError(message, option));
            }
        }
    }
}
